#include "MainMenuState.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_XAudio2.h"
#include "Game.h"
#include "GameplayState.h"
#include "CreditsState.h"
#include "OptionsState.h"
#include "HowToPlayState.h"
#include "BitmapFont.h"
#include "MenuManager.h"

/*static*/ CMainMenuState * CMainMenuState::GetInstance()
{
	static CMainMenuState s_Instance;
	return &s_Instance;
}

CMainMenuState::CMainMenuState(void)
{
	m_pD3D		= nullptr;
	m_pDI		= nullptr;
	m_pTM		= nullptr;
	m_pXA		= nullptr;
	choice = 0;

}

CMainMenuState::~CMainMenuState(void)
{
}

void CMainMenuState::Enter(void)
{
	m_pD3D	= CSGD_Direct3D::GetInstance();
	m_pDI	= CSGD_DirectInput::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();
	m_pXA	= CSGD_XAudio2::GetInstance();

	m_pBF = new CBitmapFont;
	m_pBF->Initialize();
}
void CMainMenuState::Exit()
{
	m_pD3D	= nullptr;
	m_pDI	= nullptr;
	m_pTM	= nullptr;
	m_pXA	= nullptr;
	delete m_pBF;

}		
bool CMainMenuState::Input()
{
	//close the game
	if( m_pDI->KeyPressed( DIK_ESCAPE ) )
	{
		Exit();
		return false;
	}

	if( m_pDI->KeyPressed( DIK_DOWN ) )
		{
			choice++;
			if( choice == 5 )
				choice = 0;
		}
		if( m_pDI->KeyPressed( DIK_UP ) )
		{
			choice--;
			if( choice == -1 )
				choice = 4;
		}

if( m_pDI->KeyPressed( DIK_RETURN ) && choice==0 )
	{
		CMenuManager::GetInstance()->AddMenu(CGameplayState::GetInstance() );
	}

	if( m_pDI->KeyPressed( DIK_RETURN ) && choice==1 )
	{
		CMenuManager::GetInstance()->AddMenu(COptionsState::GetInstance());

	}

	if( m_pDI->KeyPressed( DIK_RETURN ) && choice==2 )
	{
		CMenuManager::GetInstance()->AddMenu(CHowToPlayState::GetInstance() );

	}


	if( m_pDI->KeyPressed( DIK_RETURN ) && choice==3 )
	{
		CMenuManager::GetInstance()->AddMenu(CCreditsState::GetInstance() );

	}

		if( m_pDI->KeyPressed( DIK_RETURN ) && choice==4 )
		{
			Exit();
			return false;
		}

		CGame::GetInstance()->ChangeState( CMenuManager::GetInstance()->PlayBack() );

	return true;
}		
void CMainMenuState::Update(float fElapsedTime)
{
	//	time += fElapsedTime;
	//if( time >= 2 )
	//	time = 0;
}		
void CMainMenuState::Render()
{
	string word;
		word = "DODGE BALL";
		m_pBF->Print(word.c_str(), 70, 40, 1.5);
		word = "PLAY";
		m_pBF->Print(word.c_str(), 100, 100, 1);
		word = "OPTIONS";
		m_pBF->Print(word.c_str(), 100, 140, 1);
		word = "HOW TO PLAY";
		m_pBF->Print(word.c_str(), 100, 180, 1);
		word = "CREDITS";
		m_pBF->Print(word.c_str(), 100, 220, 1);
		word = "EXIT";
		m_pBF->Print(word.c_str(), 100, 260, 1);

		string enter;
		enter = "PRESS ENTER";

	m_pTM->Draw( m_nPointerImgID, 70, 100+(choice*40));

}

